unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, jpeg, Buttons;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    Label1: TLabel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    BitBtn1: TBitBtn;
    procedure Timer1Timer(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox3MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox4MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox5MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox6MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox7MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox8MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox9MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  v:array[1..8] of integer;
  i: integer;
  peso:integer;
  logo : boolean;
  y:integer;

implementation

{$R *.dfm}
function inportb(EndPorta: Integer): BYTE stdcall; external 'inpout32.DLL' name 'Inp32';
procedure outportb(EndPorta: Integer; Valor:BYTE); stdcall; external 'inpout32.DLL' name 'Out32';

procedure TForm1.Timer1Timer(Sender: TObject);
begin
for i := 1 to 8 do begin
    v[i] := 0;
end;
peso := inportb($378);
if peso >= 128 then begin
    v[8] := 1;
    peso := peso - 128;
    Image8.Visible := true;
    self.CheckBox9.Checked  := true;
    
end
else
begin
              Image8.Visible := false;
              self.CheckBox9.Checked  := false;
end;

if peso >= 64 then begin
    v[7] := 1;
    peso := peso - 64;
    Image7.Visible := true;
    self.CheckBox8.Checked  := true;
end
else
begin
    Image7.Visible := false;
    self.CheckBox8.Checked  := false;
end;
if peso >= 32 then begin
    v[6] := 1;
    peso := peso - 32;
    Image6.Visible := true;
    self.CheckBox7.Checked  := true;
end
else
begin
    Image6.Visible := false;
    self.CheckBox7.Checked  := false;
end;
if peso >= 16 then begin
    v[5] := 1;
    peso := peso - 16;
    Image5.Visible := true;
    self.CheckBox6.Checked  := true;
end
else
begin
    Image5.Visible := false;
    self.CheckBox6.Checked  := false;
end;
if peso >= 8 then begin
    v[4] := 1;
    peso := peso - 8;
    Image4.Visible := true;
    self.CheckBox5.Checked  := true;
end
else
begin
    Image4.Visible := false;
    self.CheckBox5.Checked  := false;
end;
if peso >= 4 then begin
    v[3] := 1;
    peso := peso - 4;
    Image3.Visible := true;
    self.CheckBox4.Checked  := true;
end
else
begin
    Image3.Visible := false;
    self.CheckBox4.Checked  := false;
end;
if peso >= 2 then begin
    v[2] := 1;
    peso := peso - 2;
    Image2.Visible := true;
    self.CheckBox3.Checked  := true;
end
else
begin
    Image2.Visible := false;
    self.CheckBox3.Checked  := false;
end;
if peso >= 1 then begin
    v[1] := 1;
    peso := peso - 1;
    Image1.Visible := true;
    self.CheckBox2.Checked  := true;
end
else
begin
    Image1.Visible := false;
    self.CheckBox2.Checked  := false;
end;

{if logo = true then begin
  logo := false;
for i := 0 to self.ComponentCount - 1 do begin
  for y := 1 to 8 do begin
    if ((self.Components[i] is TCheckBox)and(TCheckBox(components[i]).Caption = 'Pino' + inttostr(y))) then begin
      TCheckBox(components[i]).Checked := true;
    end
    else
    begin
        TCheckBox(components[i]).Checked := false;
    end;
   end;
end;
end;}
self.label1.Caption := inttostr(inportb($378));
end;

procedure TForm1.FormShow(Sender: TObject);
begin
logo := true;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
      if self.CheckBox1.Checked = true then begin
          outportb($378, inportb($378) - 1);
       end
       else
       begin
          outportb($378, inportb($378) + 1);
       end;
end;

procedure TForm1.CheckBox2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox2.Checked = false then begin
          if strtoint(self.Label1.Caption) < 1 then begin
              outportb($378, 1 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 1);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 1);
       end;
end;

procedure TForm1.CheckBox3MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if self.CheckBox3.Checked = false then begin
          if strtoint(self.Label1.Caption) < 2 then begin
              outportb($378, 2 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 2);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 2);
       end;
end;

procedure TForm1.CheckBox4MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox4.Checked = false then begin
          if strtoint(self.Label1.Caption) < 4 then begin
              outportb($378, 4 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 4);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 4);
       end;
end;

procedure TForm1.CheckBox5MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox5.Checked = false then begin
          if strtoint(self.Label1.Caption) < 8 then begin
              outportb($378, 8 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 8);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 8);
       end;
end;

procedure TForm1.CheckBox6MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox6.Checked = false then begin
          if strtoint(self.Label1.Caption) < 16 then begin
              outportb($378, 16 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 16);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 16);
       end;
end;

procedure TForm1.CheckBox7MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox7.Checked = false then begin
          if strtoint(self.Label1.Caption) < 32 then begin
              outportb($378, 32 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 32);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 32);
       end;
end;

procedure TForm1.CheckBox8MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox8.Checked = false then begin
          if strtoint(self.Label1.Caption) < 64 then begin
              outportb($378, 64 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 64);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 64);
       end;
end;

procedure TForm1.CheckBox9MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if self.CheckBox2.Checked = false then begin
          if strtoint(self.Label1.Caption) < 128 then begin
              outportb($378, 128 - strtoint(self.Label1.Caption));
          end
          else
          begin
              outportb($378, strtoint(self.Label1.Caption) - 128);
          end;
       end
       else
       begin
              outportb($378, strtoint(self.Label1.Caption) + 128);
       end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
outportb($378, 0);
self.BitBtn1.Enabled := false;
self.Timer1.Enabled := false;
for i := 1 to 128 do begin
    outportb($378, inportb($378) + 1);
    self.Timer1.Enabled := true;
    sleep(10);
    self.Timer1.Enabled := false;
end;
self.BitBtn1.Enabled := true;
self.Timer1.Enabled := true;
end;

end.
